home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / cmdity / yk212src.lha / Yak_2.12_Src / WBStartup / Blankers.c < prev    next >
C/C++ Source or Header  |  1996-03-03  |  6KB  |  309 lines

  1. #include <exec/memory.h>
  2. #include <graphics/gfx.h>
  3. #include <graphics/gfxbase.h>
  4. #include <graphics/gfxmacros.h>
  5. #include <graphics/displayinfo.h>
  6. #include <graphics/sprite.h>
  7. #include <hardware/custom.h>
  8. #include <hardware/dmabits.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/intuitionbase.h>
  11. #include <cybergraphics/cybergraphics.h>
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/graphics.h>
  15. #include <proto/intuition.h>
  16. #include <proto/cybergraphics.h>
  17.  
  18. #include "code.h"
  19. #include "yak.h"
  20. #include "blankers.h"
  21. #include "handlers.h"
  22. #include "settings.h"
  23.  
  24. struct Library *CyberGfxBase;
  25.  
  26. extern __far struct Custom custom;
  27.  
  28. #define TURN_OFF_SPRITES {OFF_SPRITE;custom.spr[0].dataa = custom.spr[0].datab = 0;}
  29.  
  30. static BOOL mouseoff = FALSE;           /* is mouse off? (MB_SPRITES only) */
  31. static BOOL blanked = FALSE;
  32. static struct Screen *blankscr;
  33.  
  34.  
  35. static void PowerSaveBlank(void);
  36. static void PowerSaveUnBlank(void);
  37.  
  38. static void
  39. PowerSaveBlank(void)
  40. {
  41.    if (CyberGfxBase = OpenLibrary("cybergraphics.library", 40L))
  42.    {
  43.       CVideoCtrlTags(&blankscr->ViewPort, SETVC_DPMSLevel, DPMS_OFF, TAG_DONE);
  44.    }
  45. }
  46.  
  47. static void
  48. PowerSaveUnBlank(void)
  49. {
  50.    if (CyberGfxBase != NULL)
  51.    {
  52.       CVideoCtrlTags(&blankscr->ViewPort, SETVC_DPMSLevel, DPMS_ON, TAG_DONE);
  53.  
  54.       CloseLibrary(CyberGfxBase);
  55.    }
  56. }
  57.  
  58.  
  59. static BOOL
  60. OpenBlankingScreen (void)
  61. {
  62.    ULONG modeid = INVALID_ID;
  63.    
  64.    Forbid ();
  65.    if (IntuitionBase->FirstScreen)
  66.       modeid = GetVPModeID (&(IntuitionBase->FirstScreen->ViewPort));
  67.    Permit ();
  68.    if (modeid == INVALID_ID)
  69.       modeid = LORES_KEY;
  70.    
  71.    if (blankscr = OpenScreenTags (NULL, SA_Depth, 1,
  72.                                   SA_Title, "Yak blanking screen",
  73.                                   SA_Quiet, TRUE,
  74.                                   SA_Behind, TRUE,
  75.                                   SA_DisplayID, modeid,
  76.                                   TAG_DONE))
  77.    {
  78.       SetRGB4 (&blankscr->ViewPort, 0, 0, 0, 0);
  79.       ScreenToFront (blankscr);
  80.       
  81.       return(TRUE);
  82.    }
  83.    return(FALSE);
  84. }
  85.  
  86.  
  87. static struct Window *BlankWnd;
  88.  
  89. __chip static UWORD Pointer[6] = {0,0,0,0,0,0};
  90. static BOOL OwnBlankWnd = FALSE;
  91.  
  92. static void 
  93. UnblankMousePointer( void )
  94. {
  95.    if ( BlankWnd != NULL )
  96.    {
  97.       ClearPointer( BlankWnd );
  98.  
  99.       if (OwnBlankWnd == TRUE)
  100.       {
  101.          OwnBlankWnd = FALSE;
  102.          CloseWindow( BlankWnd );
  103.       }
  104.    }
  105. }
  106.  
  107. static void 
  108. BlankMousePointer( void )
  109. {
  110.    struct Window *Win=NULL;
  111.    struct Screen *Scr;
  112.    ULONG lock;
  113.  
  114.    lock = LockIBase(0);
  115.    Win = IntuitionBase->ActiveWindow;
  116.    UnlockIBase(lock);
  117.    
  118.    if (Win == NULL)
  119.    {
  120.       Scr = ScreenUnderMouse();
  121.     
  122.       Win = OpenWindowTags (0L,
  123.                             WA_Activate, TRUE,
  124.                             WA_Left, 0,
  125.                             WA_Top, 0,
  126.                             WA_Width, 1,
  127.                             WA_Height, 1,
  128.                             WA_Borderless, TRUE,
  129.                             WA_CustomScreen, Scr,
  130.                             TAG_END );
  131.       if (Win != NULL)
  132.       {
  133.          OwnBlankWnd = TRUE;
  134.       }
  135.       else
  136.       {
  137.          OwnBlankWnd = FALSE;
  138.          return;
  139.       }
  140.    }
  141.  
  142.    if (Win != BlankWnd)
  143.    {
  144.       UnblankMousePointer();
  145.       BlankWnd = Win;
  146.    }
  147.  
  148.    SetPointer( BlankWnd, Pointer, 1, 16, 0, 0 );
  149. }    
  150.  
  151.  
  152.  
  153. void 
  154. ForceTurnMouseOff () 
  155. {
  156.    /* Force reblank */
  157.    mouseoff = FALSE;
  158.    TurnMouseOff();
  159. }
  160.  
  161. void 
  162. TurnMouseOff ()                 /* blank mouse-pointer */
  163. {
  164.    if (mouseoff == FALSE)              /* no point in turning it off twice... */
  165.    {
  166.       Forbid ();
  167.       
  168.       if (mouseblank == MB_SPRITES)
  169.       {
  170.          WaitTOF ();
  171.          OFF_SPRITE;
  172.          custom.spr[0].dataa = custom.spr[0].datab = 0;          
  173.       }
  174.       else
  175.       {
  176.          BlankMousePointer();
  177.       }
  178.       
  179.       Permit ();
  180.       
  181.       mouseoff = TRUE;
  182.    }
  183. }
  184.  
  185.  
  186. void 
  187. TurnMouseOn ()                   /* restore mouse-pointer */
  188. {
  189.    if (mouseoff == TRUE)
  190.    {
  191.       if (mouseblank == MB_SPRITES) /* really dirty blanking */
  192.       {                         /* but guaranteed to work... */
  193.          Forbid ();
  194.          WaitTOF ();
  195.          ON_SPRITE;
  196.          Permit ();
  197.       }
  198.       else
  199.       {
  200.          UnblankMousePointer();
  201.       }
  202.       mouseoff = FALSE;
  203.    }
  204. }
  205.  
  206.  
  207.  
  208. void
  209. BlankScreen ()
  210. {
  211.    switch (screenblank)
  212.    {
  213.    case SB_DMA:
  214.       if (blackborder == FALSE)
  215.       {
  216.          /* If border is not blanked, DMA blanking will use
  217.           * screen background color which something else than black
  218.           * To avoid this, we open a black screen
  219.           */
  220.          blanked = OpenBlankingScreen();
  221.       }
  222.       
  223.       /* Turn DMA off */
  224.       custom.dmacon = BITCLR|DMAF_RASTER|DMAF_COPPER|DMAF_SPRITE;  
  225.       
  226.       if (blankscr != NULL)
  227.       {
  228.          /* Close screen to save some memory, if user has chosen DMA
  229.           * blanking it, it's to save memory and CPU usage !
  230.           */
  231.          CloseScreen (blankscr);
  232.          blankscr = NULL;
  233.       }
  234.       blanked = TRUE;
  235.       break;
  236.  
  237.    case SB_BLACKSCREEN:
  238.       if (blankscr)
  239.       {
  240.          ScreenToFront (blankscr);
  241.       }
  242.       else
  243.       {
  244.          blanked = OpenBlankingScreen();
  245.       }
  246.       break;
  247.  
  248.    case SB_POWERSAVE:
  249.       if (blankscr == NULL)
  250.       {
  251.          blanked = OpenBlankingScreen();
  252.          if (blanked)
  253.          {
  254.             PowerSaveBlank();
  255.          }
  256.       }
  257.       break;
  258.    }
  259.  
  260.    /* Blank mouse in case 'DMA off' didn't work (case of PICASSO II board) */
  261.    ForceTurnMouseOff();
  262. }
  263.  
  264.  
  265. void
  266. UnBlankScreen ()
  267. {
  268.    switch (screenblank)
  269.    {
  270.    case SB_DMA:
  271.       /* Turn DMA on */
  272.       custom.dmacon = BITSET|DMAF_RASTER|DMAF_COPPER|DMAF_SPRITE;
  273.       break;
  274.  
  275.    case SB_BLACKSCREEN:
  276.       if (blankscr)
  277.       {
  278.          CloseScreen (blankscr);
  279.          blankscr = NULL;
  280.          ON_SPRITE;
  281.       }
  282.       break;
  283.  
  284.    case SB_POWERSAVE:
  285.       if (blankscr)
  286.       {
  287.          PowerSaveUnBlank();
  288.          CloseScreen (blankscr);
  289.          blankscr = NULL;
  290.          ON_SPRITE;
  291.       }
  292.       break;
  293.    }
  294.  
  295.    blanked = FALSE;
  296.    
  297. }
  298.  
  299. void
  300. UnBlankScreenAndMouse ()
  301. {
  302.    UnBlankScreen ();
  303.  
  304.    /* UnBlank mouse in case 'DMA on' or 'ON_SPRITE' didn't work (case of PICASSO II board) */
  305.    TurnMouseOn();
  306. }
  307.  
  308.  
  309.